Expand description
This crate provides the global ThreadPoolExecutor
that enables to spawn/execute fibers anywhere in a program.
This is useful for briefly writing test or example code that use fibers
.
§Examples
use fibers::sync::oneshot;
use futures::{lazy, Future};
// Spawns two auxiliary fibers.
let (tx0, rx0) = oneshot::channel();
let (tx1, rx1) = oneshot::channel();
fibers_global::spawn(lazy(move || {
let _ = tx0.send(1);
Ok(())
}));
fibers_global::spawn(lazy(move || {
let _ = tx1.send(2);
Ok(())
}));
// Executes a calculation that depends on the above fibers.
let result = fibers_global::execute(rx0.join(rx1).map(|(v0, v1)| v0 + v1));
assert_eq!(result.ok(), Some(3));
Functions§
- Executes the given future by using the global
ThreadPoolExecutor
and waits the result. - Returns the handle of the global
ThreadPoolExecutor
. - Sets the number of scheduler threads used by the global executor.
- Spawns a fiber to execute the given future by using the global
ThreadPoolExecutor
. - Spawns a fiber by using the global
ThreadPoolExecutor
and returns a future to monitor it’s execution result.